package com.company;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class ThreadTask implements Runnable{
    static int fileNumber;
    static String content;

    public static void task(int fileNumber, String content) throws IOException {
        String threadName = Thread.currentThread().getName();
        String fileName = "D:\\test\\thread" + threadName + "_";
        for (int i = 0; i < fileNumber; i++) {
            try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter( fileName + i + ".txt"))){
                bufferedWriter.write(content);
            }
        }
    }



    public ThreadTask(int fileNumber, String content) {
        this.fileNumber = fileNumber;
        this.content = content;
    }

    @Override
    public void run() {
        try {
            task(fileNumber, content);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //输出执行线程的名称
//        System.out.println("ThreadName:"+Thread.currentThread().getName());

    }
}
